package com.facebookproject.graph.element;

import static com.facebookproject.Const.URL_GRAPH;
import static com.facebookproject.Const.URL_PHOTO_SIZE_200;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.facebookproject.R;


public class ElementAdapterGridView extends ArrayAdapter<Elements>{
	private List<Elements> element;
	public List<Elements> getItems(){
		return element;
	}
	private Context context;
	private int layout;

	public List<Elements> getElement() {
		return element;
	}
	public void setElement(List<Elements> element) {
		this.element = element;
	}
	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}
	public int getLayout() {
		return layout;
	}

	public void setLayout(int layout) {
		this.layout = layout;
	}
	public ElementAdapterGridView(Context context, int textViewResourceId,List<Elements> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.element = objects;
		this.layout = textViewResourceId;
	}
	public View getView(final int position, View convertView, ViewGroup parent) {
		View v = convertView;
		URL url= null;
		ViewHolder holder = new ViewHolder();
		if (v == null) {
			LayoutInflater infalInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = infalInflater.inflate(R.layout.element_grid, null);
		}

		Elements ele = this.getItem(position);
//		TextView name = (TextView)v.findViewById(R.id.ele_name);
//		TextView line1 = (TextView)v.findViewById(R.id.ele_line1);
//		TextView line2 = (TextView)v.findViewById(R.id.ele_line2);
//		TextView line3 = (TextView)v.findViewById(R.id.ele_line3);
//		TextView line4 = (TextView)v.findViewById(R.id.ele_line4);
//		
//		name.setText(ele.getName());
//		
//		line1.setText(ele.getEle1());
//		line2.setText(ele.getEle2());
//		line3.setText(ele.getEle3());
//		line4.setText(ele.getEle4());
		
		try {
			holder.position=position;
			holder.img = (ImageView)v.findViewById(R.id.ele_img);
			holder.progress = (ProgressBar)v.findViewById(R.id.pgBarGrid);
			holder.img.setTag(position);
			holder.id = ele.getId();
			holder.dled = null;
			url = new URL(URL_GRAPH + ele.getId() +URL_PHOTO_SIZE_200);
			new LoadImageTask(holder,context).execute(url);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return v;
	}
}
